import 'package:flutter/material.dart';
import 'package:flutter_sample/src/custom/scroller/timeline_model.dart';

import 'timeline_opt_painter.dart';
import 'timeline_painter.dart';


class TimeLineChart extends LeafRenderObjectWidget {
  // 内容宽度（超出组件可视宽度才需要滑动）
  final double contentWidth;
  // 组件可视宽度
  final double visibleWidth;
  // 组件高度
  final double height;
  // 滑动内容的绘制回调
  final void Function(bool, TimeLineModel?)? callBack;

  final DateTime startDateTime;
  final DateTime endDateTime;
  /// 24 整屏宽度表示 24 小时
  /// 12 整屏宽度表示 12 小时
  /// 6 整屏宽度表示 6 小时
  final int timeType;

  final List<TimeLineModel> timeLines;

  const TimeLineChart({
    super.key,
    required this.startDateTime,
    required this.endDateTime,
    required this.timeType,
    required this.timeLines,
    required this.contentWidth,
    required this.visibleWidth,
    required this.height,
    required this.callBack,
  }) : assert(contentWidth >= visibleWidth, "内容宽度必须大于等于可视宽度");

  @override
  RenderObject createRenderObject(BuildContext context) {
    return TimeLinePainter(
      startDateTime: startDateTime,
      endDateTime: endDateTime,
      timeType: timeType,
      timeLines: timeLines,
      contentWidth: contentWidth,
      visibleWidth: visibleWidth,
      height: height,
      callBack: callBack,
    );
  }

  @override
  void updateRenderObject(BuildContext context, TimeLinePainter renderObject) {
    renderObject
      ..startTime = startDateTime
      ..endTime = endDateTime
      ..timeType = timeType
      ..timeLines = timeLines
      ..contentWidth = contentWidth
      ..visibleWidth = visibleWidth
      ..height = height
      ..callBack = callBack;
  }
}
